package com.shizhanzhe.gxb.my.activity;

import android.annotation.SuppressLint;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.shizhanzhe.gxb.R;
import com.shizhanzhe.gxb.base.UserBean;
import com.shizhanzhe.gxb.my.bean.About;
import com.shizhanzhe.gxb.url.Path;
import com.shizhanzhe.gxb.utils.OkHttpDownloadJsonUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class AboutActivity extends SwipeBackActivity {

    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.tv_kf)
    TextView tvKf;
    @BindView(R.id.tv_gw)
    TextView tvGw;
    private String kfwx = "";
    private String swwx = "";
    private String gw = "http://zhuanxiaobao.com";
    private ClipboardManager cm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarView(R.id.bar_0_view)
                .init();
        initData();
    }

    @SuppressLint("SetTextI18n")
    private void initData() {
        topTitle.setText("关于APP");
        tvKf.setText("客服微信：" + UserBean.servicewx);
        kfwx = UserBean.servicewx;
        coop();
    }

    @OnClick({R.id.top_back, R.id.kfwx, R.id.gw})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.kfwx:
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(kfwx);
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.gw:
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
                cm.setText(gw);
                break;
                default:
        }
    }
    private void coop(){
        OkHttpDownloadJsonUtil.downloadJson(this, Path.coop(), new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onsendJson(String json) {
                if (!"1".equals(json) && !"2".equals(json)){
                    try{
                        About about = new Gson().fromJson(json, About.class);
                        tvKf.setText("客服微信："+about.getData().getServicewx());
                        kfwx = about.getData().getServicewx();

                    } catch (Exception e){
                        Toast.makeText(AboutActivity.this, "数据异常", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(AboutActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
